﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GrafosWindows.Persistencia
{
    public class IOUtils
    {
        public static string OpenFileDialogShow(Form caller, string filter)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = filter;
            if (openFileDialog.ShowDialog(caller) == DialogResult.OK)
            {
                return openFileDialog.FileName;
            }

            return "";
        }

        public static string OpenFileDialogShow(Form caller)
        {
            return OpenFileDialogShow(caller, "");
        }

        public static string SaveFileDialogShow(Form caller, string filter)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = filter;
            if (saveFileDialog.ShowDialog(caller) == DialogResult.OK)
            {
                return saveFileDialog.FileName;
            }

            return "";
        }

        public static string SaveFileDialogShow(Form caller)
        {
            return SaveFileDialogShow(caller, "");    
        }

        public static void CreateTxtFile(string path, string data)
        {
            System.IO.File.WriteAllLines(path, new string[] { data });
        }

        public static string[] ReadTxtFile(string path)
        {
            if (path == null || path.Equals(""))
            {
                return new string[]{};
            }
            return System.IO.File.ReadAllLines(path);
        }
    }
}
